home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Tools / ClassAct / Examples / Connect / ConnectExample.c < prev    next >
C/C++ Source or Header  |  1997-04-27  |  5KB  |  184 lines

  1. /* ClassAct Inter-Connection Notification Example
  2.  */
  3. #include <clib/macros.h>
  4. #include <clib/alib_protos.h>
  5. #include <libraries/gadtools.h>
  6. #include <intuition/icclass.h>
  7.  
  8. #include <proto/exec.h>
  9. #include <proto/dos.h>
  10. #include <proto/utility.h>
  11. #include <proto/graphics.h>
  12. #include <proto/intuition.h>
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #include <classact.h>
  19. #include <classact_author.h>
  20.  
  21. #define ID_BUTTON       1
  22. #define ID_FOREGROUND      2
  23. #define ID_BACKGROUND    3
  24.  
  25. struct ClassLibrary *WindowBase;
  26. struct ClassLibrary *LayoutBase;
  27. struct ClassLibrary *LabelBase;
  28. struct ClassLibrary *ButtonBase;
  29. struct ClassLibrary *PaletteBase;
  30.  
  31. int main( int argc, char *argv[] )
  32. {
  33.     struct Window *window;
  34.     Object *But_Object;
  35.     Object *Win_Object;
  36.  
  37.     /* Palette Color To Button ForeGround mapping.
  38.      */
  39.     struct TagItem MapFG2Button[] =
  40.     {
  41.         PALETTE_Color, BUTTON_TextPen,
  42.         TAG_END
  43.     };
  44.  
  45.     /* Palette Color To Button BackGround mapping.
  46.      */
  47.     struct TagItem MapBG2Button[] =
  48.     {
  49.         PALETTE_Color, BUTTON_BackgroundPen,
  50.         TAG_END
  51.     };
  52.  
  53.     /* Open the classes - typically not required to be done manually.
  54.      * SAS/C or DICE AutoInit can do this for you if linked with the
  55.      * supplied classact.lib
  56.      */
  57.     WindowBase = (struct ClassLibrary *)OpenLibrary("window.class",0L);
  58.     LayoutBase = (struct ClassLibrary *)OpenLibrary("gadgets/layout.gadget",0L);
  59.     ButtonBase = (struct ClassLibrary *)OpenLibrary("gadgets/button.gadget",0L);
  60.     PaletteBase = (struct ClassLibrary *)OpenLibrary("gadgets/palette.gadget",0L);
  61.     LabelBase = (struct ClassLibrary *)OpenLibrary("images/label.image",0L);
  62.  
  63.     if(WindowBase && LayoutBase && ButtonBase && PaletteBase && LabelBase)
  64.     {
  65.         /* Create the window object.
  66.          */
  67.         Win_Object = WindowObject,
  68.             WA_ScreenTitle, "ClassAct Copyright 1995, Phantom Development LLC.",
  69.             WA_Title, "ClassAct Example",
  70.             WA_SizeGadget, TRUE,
  71.             WA_Left, 40,
  72.             WA_Top, 30,
  73.             WA_DepthGadget, TRUE,
  74.             WA_DragBar, TRUE,
  75.             WA_CloseGadget, TRUE,
  76.             WA_Activate, TRUE,
  77.             WA_SmartRefresh, TRUE,
  78.             WINDOW_ParentGroup, VLayoutObject,
  79.                 LAYOUT_SpaceOuter, TRUE,
  80.                 LAYOUT_DeferLayout, TRUE,
  81.                 LAYOUT_BevelStyle, GroupFrame,
  82.                 LAYOUT_Label, "InterConnection",
  83.                 StartMember, But_Object = ButtonObject,
  84.                     GA_Text, "_Inter-Connection Example",
  85.                     GA_ID, ID_BUTTON,
  86.                 EndMember,
  87.                 CHILD_WeightedHeight, 0,
  88.  
  89.                 StartMember, HLayoutObject,
  90.                     LAYOUT_SpaceOuter, FALSE,
  91.                     StartMember, PaletteObject,
  92.                         GA_ID, ID_FOREGROUND,
  93.                         PALETTE_NumColors, 8,
  94.                         PALETTE_Color, 1,
  95.                         ICA_TARGET, But_Object, /* object to connect to */
  96.                         ICA_MAP, MapFG2Button, /* tag mapping array */
  97.                     EndMember,
  98.                     CHILD_Label, LabelObject, LABEL_Text, "_ForeGround", LabelEnd,
  99.                     CHILD_MinWidth, 90,
  100.                     CHILD_MinHeight, 20,
  101.     
  102.                     StartMember, PaletteObject,
  103.                         GA_ID, ID_BACKGROUND,
  104.                         PALETTE_NumColors, 8,
  105.                         PALETTE_Color, 0,
  106.                         ICA_TARGET, But_Object, /* object to connect to */
  107.                         ICA_MAP, MapBG2Button, /* tag mapping array */
  108.                     EndMember,
  109.                     CHILD_Label, LabelObject, LABEL_Text, "_BackGround", LabelEnd,
  110.                     CHILD_MinWidth, 90,
  111.                     CHILD_MinHeight, 20,
  112.                 EndMember,
  113.             EndMember,
  114.         EndWindow;
  115.  
  116.         /*  Object creation sucessful?
  117.          */
  118.         if( Win_Object )
  119.         {
  120.             /*  Open the window.
  121.              */
  122.             if( window = (struct Window *) CA_OpenWindow(Win_Object) )
  123.             {
  124.                 ULONG wait, signal, result, done = FALSE;
  125.                 WORD Code;
  126.                 
  127.                 /* Obtain the window wait signal mask.
  128.                  */
  129.                 GetAttr( WINDOW_SigMask, Win_Object, &signal );
  130.  
  131.                 /* Input Event Loop
  132.                  */
  133.                 while( !done )
  134.                 {
  135.                     wait = Wait(signal|SIGBREAKF_CTRL_C);
  136.                     
  137.                     if (wait & SIGBREAKF_CTRL_C) done = TRUE;
  138.                     else
  139.  
  140.                     while ((result = CA_HandleInput(Win_Object,&Code)) != WMHI_LASTMSG)
  141.                     {
  142.                         switch (result & WMHI_CLASSMASK)
  143.                         {
  144.                             case WMHI_CLOSEWINDOW:
  145.                                 done = TRUE;
  146.                                 break;
  147.  
  148.                             case WMHI_GADGETUP:
  149.                                 switch(result & WMHI_GADGETMASK)
  150.                                 {
  151.                                     case ID_BUTTON:
  152.                                         break;
  153.                                 }
  154.                                 break;
  155.                         }
  156.                     }
  157.                 }
  158.             }
  159.  
  160.             /* Disposing of the window object will
  161.              * also close the window if it is
  162.              * already opened and it will dispose of
  163.              * all objects attached to it.
  164.              */
  165.             DisposeObject( Win_Object );
  166.         }
  167.     }
  168.  
  169.     /* Close the classes.
  170.      */
  171.     if (LabelBase)        CloseLibrary( (struct Library *)LabelBase );
  172.     if (PaletteBase)    CloseLibrary( (struct Library *)PaletteBase );
  173.     if (ButtonBase)        CloseLibrary( (struct Library *)ButtonBase );
  174.     if (LayoutBase)        CloseLibrary( (struct Library *)LayoutBase );
  175.     if (WindowBase)        CloseLibrary( (struct Library *)WindowBase );
  176. }
  177.  
  178. #ifdef _DCC
  179. int wbmain( struct WBStartup *wbs )
  180. {
  181.         return( main( 0, NULL ));
  182. }
  183. #endif
  184.